
import { CommandService } from '@farris/command-services';
import { Injectable } from '@angular/core';
import {FrameContext,BindingData,Repository} from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import {  BeActionService, FormMessageService ,FormNotifyService } from '@farris/command-services';
import { tap,switchMap } from 'rxjs/operators'
@Injectable()
export class SbssLuStandFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private commandService: CommandService,
    private beActionService: BeActionService,
    private messageService: FormNotifyService
  ) {}

  /**
   * 刷新左侧导航
   * @remarks 
   * @returns 
   */
  reflashTree(): any {
    this.commandService.execute("LoadTree1","sbssLuTree-bel1-component_sbsslutree_tree-grid-component");
  }

  /**
   * 开启标准
   */
  ActiveStand(): any {
    let rowData = this['context'].eventParam.rowData;//获取整行数据
    let id = rowData.id
    let active = rowData.luActive

    const rep = this.frameContext.repository as BefRepository<any>;
    const repInfo = rep.restService.buildRequestInfo();

    const actionUri = 'activestand';
    const body = {
      id: id,
      active:active,
      requestInfo: repInfo
    }

    const action$ = this.beActionService.invokeAction(actionUri, 'PUT', null, null, body);
    return action$.pipe(
      tap((responseInfo: ResponseInfo) => {
        let msg = ""
        if(active){
          msg = "标准已开启!"
        }else{
          msg = "标准已关闭!"
        }
        this.messageService.info(msg);
        this.commandService.execute("Filter1","root-component");
      }))  
  }

  /**
   * 开启标准
   */
  ActiveListStand(id,active): any {


    const rep = this.frameContext.repository as BefRepository<any>;
    const repInfo = rep.restService.buildRequestInfo();

    if (active == "true"){
      active = true
    }else{
      active = false
    }

    const actionUri = 'activestandlist';
    const body = {
      ids: id,
      active:active,
      requestInfo: repInfo
    }

    const action$ = this.beActionService.invokeAction(actionUri, 'PUT', null, null, body);
    return action$.pipe(
      tap((responseInfo: ResponseInfo) => {
        let msg = ""
        if(active){
          msg = "标准已开启!"
        }else{
          msg = "标准已关闭!"
        }
        this.messageService.info(msg);
        this.commandService.execute("Filter1","root-component");
      }))  
  }
}
